package com.itheima.app.utils;

import com.itheima.util.ConstantUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

//定时任务
@Component
public class Crontab {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    //编写定时删除redis中的桃花传音 用户使用次数、、
//    @Scheduled(cron = "0 0 0 * * ?")
    @Scheduled(cron = "0 0/10 * * * ?")
    public void deleteVoiceTime(){
        //redisTemplate模糊匹配删除
        //返回值 为  删除的个数
        Long delete = stringRedisTemplate.delete(stringRedisTemplate.keys(ConstantUtil.VOICE_USER_GET_TIME + "*"));
        stringRedisTemplate.delete(stringRedisTemplate.keys(ConstantUtil.VOICE_USER_SET_TIME + "*"));
        System.out.println("刷新了 缓存 @！！！");
    }

}
